/*
 * GroupValueDisplay.java
 *
 * Created on 03 January 2004, 07:47
 * Copyright (C) 2004, Velocityme Partnership
 */

package com.velocityme.client.gui.node.group;

import com.velocityme.client.gui.ListAssignPanel;
import com.velocityme.valueobjects.GroupValue;
import com.velocityme.valueobjects.NodeValue;
import com.velocityme.valueobjects.UserValue;
import com.velocityme.valueobjects.UserValueToString;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 *
 * @author  Robert Crida Work
 */
public class GroupValueDisplay extends javax.swing.JPanel {
    
    private GroupValue m_groupValue;
    private ListAssignPanel m_listAssignPanel;
    
    /** Creates new form GroupValueDisplay */
    public GroupValueDisplay(GroupValue p_groupValue, Collection p_allUserValues, Collection p_assignedUserValues) {
        initComponents();
        java.awt.GridBagConstraints gridBagConstraints;
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.gridx = 2;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.5;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 0);
        add(m_listAssignPanel = new ListAssignPanel(p_allUserValues), gridBagConstraints);
        setGroupValue(p_groupValue, p_allUserValues, p_assignedUserValues);
    }
    
    public void setGroupValue(GroupValue p_groupValue, Collection p_allUserValues, Collection p_assignedUserValues) {
        NodeValue nodeValue = p_groupValue.getNodeValue();
        if (nodeValue != null) {
            if (nodeValue.nameHasBeenSet())
                jTextFieldName.setText(nodeValue.getName());
            if (nodeValue.descriptionHasBeenSet())
                jTextAreaDescription.setText(nodeValue.getDescription());
        }
        m_listAssignPanel.setAssignedValues(p_assignedUserValues);
        m_groupValue = p_groupValue;
    }
    
    public GroupValue getGroupValue() {
        if (m_groupValue.getNodeValue() == null)
            m_groupValue.setNodeValue(new NodeValue());
        m_groupValue.getNodeValue().setName(jTextFieldName.getText());
        m_groupValue.getNodeValue().setDescription(jTextAreaDescription.getText());
        return m_groupValue;
    }
    
    public Collection getUserValues() {
        if (m_listAssignPanel != null)
            return m_listAssignPanel.getAssignedValues();
        else
            return null;
    }
    
    public void setEditable(boolean p_editable) {
        jTextFieldName.setEditable(p_editable);
        jTextAreaDescription.setEditable(p_editable);
        m_listAssignPanel.setEnabled(p_editable);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        jLabelIcon = new javax.swing.JLabel();
        jLabelUserName = new javax.swing.JLabel();
        jTextFieldName = new javax.swing.JTextField();
        Description = new javax.swing.JLabel();
        jScrollPaneDescription = new javax.swing.JScrollPane();
        jTextAreaDescription = new javax.swing.JTextArea();
        jLabelUsers = new javax.swing.JLabel();

        setLayout(new java.awt.GridBagLayout());

        jLabelIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/velocityme/client/icons/group-32x32.png")));
        add(jLabelIcon, new java.awt.GridBagConstraints());

        jLabelUserName.setText("Name:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jLabelUserName, gridBagConstraints);

        jTextFieldName.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jTextFieldName, gridBagConstraints);

        Description.setText("Description:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(Description, gridBagConstraints);

        jTextAreaDescription.setEditable(false);
        jTextAreaDescription.setLineWrap(true);
        jTextAreaDescription.setWrapStyleWord(true);
        jScrollPaneDescription.setViewportView(jTextAreaDescription);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 0.5;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jScrollPaneDescription, gridBagConstraints);

        jLabelUsers.setText("Users:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(jLabelUsers, gridBagConstraints);

    }//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Description;
    private javax.swing.JLabel jLabelIcon;
    private javax.swing.JLabel jLabelUserName;
    private javax.swing.JLabel jLabelUsers;
    private javax.swing.JScrollPane jScrollPaneDescription;
    private javax.swing.JTextArea jTextAreaDescription;
    private javax.swing.JTextField jTextFieldName;
    // End of variables declaration//GEN-END:variables
    
}
